package com.fqcar.fqdf.plugin.image;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.github.chrisbanes.photoview.PhotoView;
import com.fqcar.fqdf.R;

import java.util.List;

/**
 * @author 张枭
 * @version V1.0
 * @date 2017/7/3
 * @desc
 */
public class ImagePagerAdapter extends PagerAdapter {

    private List<ImageZoomBean> mDataList;
    private LayoutInflater inflater;
    private Context context;

    public ImagePagerAdapter(Context context, List<ImageZoomBean> dataList) {
        mDataList = dataList;
        inflater = LayoutInflater.from(context);
        this.context = context;
    }

    public void setDataList(List<ImageZoomBean> dataList) {
        mDataList = dataList;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }


    @Override
    public int getCount() {
        return mDataList.size();
    }

    public ImageZoomBean getItemData(int position) {
        return mDataList.get(position);
    }

    @Override
    public Object instantiateItem(ViewGroup view, int position) {

        View v = inflater.inflate(R.layout.activity_image_zoom_item, view, false);
        PhotoView curImageView = (PhotoView) v.findViewById(R.id.img_zoom_photo);
        curImageView.setMaximumScale(2);
        curImageView.setMinimumScale(1);
        final ImageZoomBean mData = mDataList.get(position);

        curImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickItemListener(mData);
            }
        });

        Glide.with(context).load(mData.getImgUrl()).into(curImageView);

        view.addView(v, 0);
        return v;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view.equals(object);
    }

    public void clickItemListener(ImageZoomBean item){

    }
}
